package com.jinlejia.erp.ui.common;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.erp.R;

/**
 * 打电话对话框
 */

public class CallAndMessageDialog extends AlertDialog implements View.OnClickListener{

    private String name,phone;

    public CallAndMessageDialog(Context context) {
        super(context);
    }
    public CallAndMessageDialog(Context context,String name,String phone) {
        super(context);
        this.name = name;
        this.phone = phone;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.dialog_call_and_message);
        window.setGravity(Gravity.BOTTOM);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //姓名&电话
        TextView namePhone = (TextView) window.findViewById(R.id.name_phone);
        //打电话
        TextView call = (TextView) window.findViewById(R.id.call_btn);
        //发消息
        TextView message = (TextView) window.findViewById(R.id.message);

        call.setOnClickListener(this);
        message.setOnClickListener(this);
        namePhone.setText(name.concat(" : ").concat(phone));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.call_btn:
                //打电话
                if(null != listener)
                listener.onCall();
                dismiss();
                break;
            case R.id.message:
                //发消息
                dismiss();
                if( null != listener )
                listener.onMessage();
                break;
            default:
                dismiss();
                break;
        }
    }

    public interface OnCallListener {
         void onCall();
        void onMessage();
    }

    private OnCallListener listener;

    public void setOnCallListener(OnCallListener listener) {
        this.listener = listener;
    }
}
